package leetcode

type NumArray struct {
	numSum []int
}

func Constructor(nums []int) NumArray {
	res := NumArray{numSum: make([]int, len(nums))}
	res.numSum[0] = nums[0]
	length := len(nums)
	for i := 1; i < length; i++ {
		res.numSum[i] = res.numSum[i-1] + nums[i]
	}
	return res
}

func (this *NumArray) SumRange(left int, right int) int {
	if left > 0 {
		return this.numSum[right] - this.numSum[left-1]
	} else {
		return this.numSum[right]
	}
}
